﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.Services;
using System.Collections.Specialized;
using AjaxControlToolkit;

using System.Linq;
namespace Yu.Cms.Web
{
    /// <summary>
    /// CarsService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://www.cnkker.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class CarsService : System.Web.Services.WebService
    {
        
        [WebMethod]
        public CascadingDropDownNameValue[] GetBigTypeList(string knownCategoryValues, string category)
        {
            Yu.Cms.BLL.BigType bllBig = new Yu.Cms.BLL.BigType();          
            IList<Yu.Cms.Model.BigType> lst= bllBig.GetList();
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            for (int i = 0; i < lst.Count;i++ )
            {
                string BigTypeName = lst[i].BigTypeName;
                int BigTypeID = lst[i].BigTypeID;
                values.Add(new CascadingDropDownNameValue(
                  BigTypeName, BigTypeID.ToString()));
            }
            return values.ToArray();
        }

        [WebMethod]
        public CascadingDropDownNameValue[] GetSmallTypeList(string knownCategoryValues,string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            int BigTypeID;
            if (!kv.ContainsKey("BigTypeName") || !Int32.TryParse(kv["BigTypeName"], out BigTypeID))
            {
                return null;
            }

            Yu.Cms.BLL.SmallType bllSmall = new Yu.Cms.BLL.SmallType();
            IList<Yu.Cms.Model.SmallType> lst = bllSmall.GetList(BigTypeID);
            IList<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            for (int i = 0; i < lst.Count; i++)
            {
                string SmallTypeName = lst[i].SmallTypeName;
                int SmallTypeID = lst[i].SmallTypeID;
                values.Add(new CascadingDropDownNameValue(SmallTypeName, SmallTypeID.ToString()));
            }
            return values.ToArray();             
        }
    }
}
